<?php
class IndexController extends  Controller{

	
	public function index(){
		$this->getSmarty();
		$sql ="select count(*) postcount,(select count(*) from users) usercount,(select count(*) from post_comments) commentscount,(select count(*) from tags) tagcount from posts";
        $dbutil = $this->getDB();
        $datacount = $dbutil->get_row($sql);
        //任务统计
        $this->smarty->assign("datacount",$datacount);
        //近期变化统计
        $neartsql="SELECT	DATE_FORMAT(po.post_date, '%y-%m-%d') postdate,COUNT(po.ID) postcount,(select count(*) from post_comments where DATE_FORMAT(comment_date, '%y-%m-%d')=postdate) commentcount FROM posts po WHERE	post_date >= DATE_SUB(CURDATE(), INTERVAL 7 DAY) GROUP BY	postdate";
        $neardata = $dbutil->get_results($neartsql,ARRAY_N);
        $this->smarty->assign("neardata",$neardata);
        
    	//用户统计
		$usersql = "select (select count(*) from users where login_type=0) type0,(select count(*) from users where login_type=1) type1, (select count(*) from users where login_type=2) type2 from users  limit 1,1";
		$usercount = $dbutil->get_row($usersql);
		$this->smarty->assign("usercount",$usercount);
		$this->smarty->display("admin/index.tpl");
    }
}